
package common.packet;


/**
 * Interface for all packet handlers.
 *
 * @author xissburg
 */
public interface PacketHandler
{
    /**
     * Handles a packet of the type returned by getPacketCode(). If packet
     * handlers are only used within a ReceiveHandleLoop it is assured that the
     * packet given as argument to any call of this method is of the corresponding
     * Packet-derived class which its getCode() method returns the same Code
     * getPacketCode() returns here, thus it is safe to downcast the argument in
     * this context with a exception-free guarantee.
     *
     * @param packet the packet to be handled.
     */
    public void handle(Packet packet);

    /**
     * Returns the code of the packet type this packet handler handles. Useful
     * for mapping packet code to handlers.
     * @return the code of the packet type this packet handler handles
     */
    public Packet.Code getPacketCode();
}
